package com.gopay.common.domain.cbrmb;

import java.io.File;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.gopay.common.domain.BaseEntity;
import com.gopay.common.util.cbrmb.Digests;
import com.gopay.common.util.cbrmb.MsgUtils;

/**
 * 
 * @ClassName: CbRmbBankMessageDtl
 * @Description: 报盘/回盘 通知报文说明
 * @author gd.cui
 * @date 2016年6月29日 下午3:01:48 ww.gopay.com.cn Inc.All rights reserved.
 */
@Entity
@Table(name = "CB_RMB_BANK_MESSAGE_DTL")
public class CbRmbBankMessageDtl extends BaseEntity {

    /**
     * @Fields serialVersionUID
     */
    private static final long serialVersionUID = 3923818844451534852L;

    @Id
    @SequenceGenerator(name = "CB_RMB_BANK_MESSAGE_SEQ", sequenceName = "CB_RMB_BANK_MESSAGE_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CB_RMB_BANK_MESSAGE_SEQ")
    @Column(name = "MESSAGE_ID")
    private int messageId;

    /**
     * 数据信息头 id cbbankordermessagerel orderMessageId
     */
    @Column(name = "ORDER_MESSAGE_ID")
    private int orderMessageId;

    /**
     * 通知方标识 建行发起固定-CCBS； 支付机构发起固定-GOPS;
     */
    @Column(name = "SENDER_ID")
    private String senderId;

    /**
     * 交易类型 01-来盘，02-回盘
     */
    @Column(name = "TRAN_TYPE")
    private String tranType;
    /**
     * 交易日期 yyyyMMdd
     */
    @Column(name = "TRAN_DATE")
    private String tranData;
    /**
     * 交易时间 HHmmss
     */
    @Column(name = "TRAN_TIME")
    private String tranTime;
    /**
     * 交易流水 唯一标识每一笔通知，yyyyMMddHHmmss+3位序号
     */
    @Column(name = "TRAN_SN")
    private String tranSn;
    /**
     * 文件名 来盘文件名按KJZFLP_yyyyMMdd_三位序号.xml； 回盘文件按KJZFHP_yyyyMMdd_三位序号.xml； 不带目录路径
     * 
     */
    @Column(name = "FILE_NAME")
    private String fileName;
    /**
     * mac 存来盘/回盘文件SHA1校验值，用于内容有效性校验，40位长度大写表示
     */
    @Column(name = "MAC")
    private String mac;

    /**
     * 返回码 000000:请求接收成功 900001:文件名重复 900002:文件不存在 900003：文件HASH值校验失败
     * 900004:其它错误
     * 
     */
    @Column(name = "RET_CODE")
    private String retCode;
    /**
     * 返回说明
     */
    @Column(name = "RET_MSG")
    private String retMsg;

    /**
     * 创建时间
     */
    @Column(name = "CREATE_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    /**
     * 最后更新时间
     */
    @Column(name = "LAST_UPDATE_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdateTime;

    public int getMessageId() {
        return messageId;
    }

    public void setMessageId(int messageId) {
        this.messageId = messageId;
    }

    public int getOrderMessageId() {
        return orderMessageId;
    }

    public void setOrderMessageId(int orderMessageId) {
        this.orderMessageId = orderMessageId;
    }

    public String getSenderId() {
        return senderId;
    }

    public void setSenderId(String senderId) {
        this.senderId = senderId;
    }

    public String getTranType() {
        return tranType;
    }

    public void setTranType(String tranType) {
        this.tranType = tranType;
    }

    public String getTranData() {
        return tranData;
    }

    public void setTranData(String tranData) {
        this.tranData = tranData;
    }

    public String getTranTime() {
        return tranTime;
    }

    public void setTranTime(String tranTime) {
        this.tranTime = tranTime;
    }

    public String getTranSn() {
        return tranSn;
    }

    public void setTranSn(String tranSn) {
        this.tranSn = tranSn;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    public String getRetCode() {
        return retCode;
    }

    public void setRetCode(String retCode) {
        this.retCode = retCode;
    }

    public String getRetMsg() {
        return retMsg;
    }

    public void setRetMsg(String retMsg) {
        this.retMsg = retMsg;
    }

    public CbRmbBankMessageDtl() {

    }

    public CbRmbBankMessageDtl(File file) {
        Date date = new Date();
        this.senderId = "GOPS";
        this.tranType = "01";
        this.tranTime = MsgUtils.date2StrHHMMSS(date);
        this.tranData = MsgUtils.date2StrYYYYMMDD(date);
        this.tranSn = MsgUtils.date2StrYYYYMMDDHHMMSS(date) + MsgUtils.getMessageSeq();
        this.fileName = file.getName();
        this.mac = Digests.getSha1Str(file);
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

}
